/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: DynamicFragment
 * Author: Gxjkz
 * Date: 2021/7/14 13:38
 * Description: 个人动态
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Fragment;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseFragment;
import com.niuxiaofa.newlaw.Base.RefreshInterface;
import com.niuxiaofa.newlaw.Bean.VideosBean;
import com.niuxiaofa.newlaw.Network.MePresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.adapter.VideoAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @ClassName: DynamicFragment
 * @Description: java类作用描述
 * @Author: Gxjkz
 * @Date: 2021/7/14 13:38
 */
public class VideoFragment extends BaseFragment implements MePresenter.interface_mineVideos, RefreshInterface.Refresh {

    int currentIndex = 1;

    VideoAdapter videoAdapter;

    List<VideosBean.DataDTO> dataDTOList = new ArrayList<>();

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;


    @Override
    protected int getLayoutId() {
        return R.layout.view_recyclerview;
    }

    @Override
    public void initData() {
        refreshinterface = new RefreshInterface(this);
        Map map = new HashMap();
        map.put("url", "");
        map.put("viewAuthority", "");
        map.put("uploadAddress", "");
        map.put("videoTotalTime", "");
        map.put("coverImageUrl", "");
        map.put("content", "");
        map.put("label", "");

        //  MePresenter.uploadVideo(map, this);


        MePresenter.mineVideos(currentIndex, this);

        videoAdapter = new VideoAdapter(dataDTOList, new VideoAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });

        RecyclerViewHelp.setRecyclerGridLayout(recyclerview, 0, 2).setAdapter(videoAdapter);


//        MePresenter. community(map, new MePresenter.interface_community() {
//            @Override
//            public void getResponse(BaseBean u) {
//
//            }
//        });


    }

//    @Override
//    public void getResponse(ByUserBean u) {
//        if (u.getCode() == 1) {
//
//            if (refreshLayout != null) {
//                refreshLayout.finishRefresh();
//                refreshLayout.finishLoadMore();
//            }
//            if (currentIndex==1){
//                dataDTOList.clear();
//            }
//
//            dataDTOList.addAll(u.getData());
//            videoAdapter.notifyDataSetChanged();
//        }
//    }

    @Override
    public void refresh() {
        currentIndex = 1;
        MePresenter.mineVideos(currentIndex, this);
    }

    @Override
    public void loadmore() {
        currentIndex++;
        MePresenter.mineVideos(currentIndex, this);
    }


    @Override
    public void getResponse(VideosBean u) {
        if (u.getCode() == 1) {

            if (currentIndex == 1) {
                dataDTOList.clear();
            }
            if (refreshLayout != null) {
                refreshLayout.finishLoadMore();
                refreshLayout.finishRefresh();
            }

            dataDTOList.addAll(u.getData());
            videoAdapter.notifyDataSetChanged();

        }
    }
}